(function($) {

	$.SJR = function(){};

	$.SJR.SIMPLE_JSON_REST = "1.0.0"

	$.SJR.option = {
		"type" : "",
		"url"  : "",
	};

	$.SJR.clear = function(){
		$.SJR.option.data = {};
		$.SJR.option.success = function(response, status){console.log('ajax success');};
		$.SJR.option.error = function(xhr, status, thrown){console.log('ajax error');};
	};
	$.SJR.clear();

	$.SJR.ajax = function() {
		$.ajax($.SJR.option);
	};

	$.SJR.ajaxbase = function(m, config, success, error){
		$.SJR.clear();
		$.SJR.option.data = config;
		$.SJR.option.type = m;
		if(success) $.SJR.option.success = success;
		if(error) $.SJR.option.error = error;
		$.ajax($.SJR.option);
	};

	$.extend({
		_GET : function(config, success, error) {
			$.SJR.ajaxbase("GET", config, success, error);
			return this;
		},
		_POST : function(config, success, error) {
			$.SJR.ajaxbase("POST", config, success, error);
			return this;
		},
		_PUT : function(config, success, error) {
			$.SJR.ajaxbase("PUT", config, success, error);
			return this;
		},
		_DELETE : function(config, success, error) {
			$.SJR.ajaxbase("DELETE", config, success, error);
			return this;
		}
	});
	$.fn.extend({
		_GET : function(success, error) {
			$.SJR.option.url = this.attr('action');
			$.SJR.ajaxbase('GET', this.values(), success, error);
			return this;
		},
		_POST : function(success, error) {
			$.SJR.option.url = this.attr('action');
			$.SJR.ajaxbase('POST', this.values(), success, error);
			return this;
		},
		_PUT : function(success, error) {
			$.SJR.option.url = this.attr('action');
			$.SJR.ajaxbase('PUT', this.values(), success, error);
			return this;
		},
		_DELETE : function(success, error) {
			$.SJR.option.url = this.attr('action');
			$.SJR.ajaxbase('DELETE', this.values(), success, error);
			return this;
		}
	});
})(jQuery);

